#include "rate.hpp"
rate::rate(){
  acc=gsl_interp_accel_alloc();
  spline=gsl_spline_alloc(gsl_interp_cspline,3);
  n=0;
  dt=0;
}

rate::~rate(){
  gsl_interp_accel_free(acc);
  gsl_spline_free(spline);
}

rate::rate(vector<double> d,double delta_t){
  n=d.size();
  dt=delta_t;
  
  double *t=new double[n];
  for(int ii=0;ii<n;ii++){
    t[ii]=ii*dt;
  }
  
  acc=gsl_interp_accel_alloc();
  spline=gsl_spline_alloc(gsl_interp_cspline,n);
  //Pointer to beginning of array
  gsl_spline_init(spline,t,d.data().begin(),n);
  delete[] t;
}

rate::rate(const rate& d){
  if(this != &d){
    acc=gsl_interp_accel_alloc();
    spline=gsl_spline_alloc(gsl_interp_cspline,d.spline->size);
    gsl_spline_init(spline,d.spline->x,d.spline->y,d.spline->size);
    n=d.n;
    dt=d.dt;
  }
}        

rate& rate::operator=(const rate& d){
  if(this != &d){
    acc=gsl_interp_accel_alloc();
    spline=gsl_spline_alloc(gsl_interp_cspline,d.spline->size);
    gsl_spline_init(spline,d.spline->x,d.spline->y,d.spline->size);
    n=d.n;
    dt=d.dt;
  }
  return *this;
}

double rate::operator()(double t){
  return gsl_spline_eval(spline,t,acc);
}


